import os
import  pymysql



def getConn(host, user, pwd, db):
    conn = pymysql.Connect(host=host, user=user, passwd=pwd, db=db, charset="utf8", use_unicode="True")
    return conn


def insert(sql, conn):
    cursor = conn.cursor()
    cursor.execute(sql)
    conn.commit()



def defaultconfig(database):
    host="localhost"
    user="root"
    pwd="joinx-yang"
    conn=getConn(host,user,pwd,database)
    # insert("insert into student(id,`name`) values(%s,'%s') "%('23',"张三"),conn)
    return conn
def update(sql, conn):
    cursor = conn.cursor()
    cursor.execute(sql)
    conn.commit()


def selectRows(sql, conn):
    cursor = conn.cursor()
    cursor.execute(sql)
    conn.commit()
    rows = cursor.fetchall()
    return rows


def closeConn(conn):
    conn.close()